<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/view/common/header-company.jspf"%>
<div class="container">
	<center>
		<h1>企业招聘信息</h1>
	</center>
	<span class="pull-right"><a
		href="<%=request.getContextPath()%>/view/company/position-add.jsp">发布职位</a></span>
		
	<table class="table table-striped ">
		<tr>
			<th>序 号</th>
			<th>职位名称</th>
			<th>主要任务</th>
			<th>能力需求</th>
			<th>最低工资</th>
			<th>最高工资</th>
			<th>发布时间</th>
			<th>操作</th>
		</tr>

		<!--  foreach  展示个人简历信息 -->
		
		<c:forEach items="${requestScope.pageModelp.list }" var="position"
			varStatus="v">
			
			
			<tr>
				<td>${v.count + (pageModelp.pageNum-1) * 6}</td>
				<td><a href="javascript:showInfo();">${position.name }</a></td>
				<td>${position.duty}</td>
				<td>${position.ability}</td>
				<td>${position.salary1}</td>
				<td>${position.salary2}</td>
				<td>${position.releaseTimeStr}</td>
				<td>
					<div class="btn-group">
						<button type="button" class="btn btn-warning dropdown-toggle"
							data-toggle="dropdown">
							编辑 <span class="caret"></span>
						</button>
						<ul class="dropdown-menu" role="menu">
							<li><a
					href="<%=request.getContextPath()%>/PositionServlet?command=preUpdatePosition&positionId=${position.id }">修改</a></li>
							<li><a onclick="deletePosition(this,${position.id });">删除</a></li>
						</ul>
					</div>
				</td>
			</tr>
		</c:forEach>

		<c:if test="${empty requestScope.positionList  }">
		<tr>
		<td colspan="8" align="center" class="alert alert-danger" role="alert">没有相关数据</td>
		</tr>
		</c:if>
		
	</table>
	
	<c:choose>
			<c:when test="${pageModelp.totalPages <= 10 }">
				<c:set var="begin" value="1" />
				<c:set var="end" value="${pageModelp.totalPages }" />
			</c:when>
			<c:otherwise>
			<%-- 当总页数>10时，通过公式计算出begin和end --%>
			<c:set var="begin" value="${pageModelp.pageNum-5 }" />
				<c:set var="end" value="${pageModelp.pageNum+4 }" /> 
				<c:if test="${begin < 1 }">
				<c:set var="begin" value="1" />
				<c:set var="end" value="10" />
				</c:if> 
				<c:if test="${end > pageModelp.totalPages }">
				<c:set var="begin" value="${pageModelp.totalPages - 9 }" />
				<c:set var="end" value="${pageModelp.totalPages }" />
				</c:if> 
				</c:otherwise>
					</c:choose>
			<%-- 循环遍历页码列表 --%>
			<center>
			<nav><ul class="pagination">
			 <li <c:if test="${pageModelp.pageNum eq 1}"> class="disabled"</c:if>><a href="<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=1"><span>-&infin;</span></a></li>
			 <li <c:if test="${pageModelp.pageNum eq 1}"> class="disabled"</c:if>><a href="<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=${pageModelp.pageNum-1}"><span>&laquo;</span></a></li>
			<c:forEach var="i" begin="${begin }" end="${end }">
    		 <li <c:if test="${pageModelp.pageNum eq i}">class="active" </c:if>><a href="<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=${i }">${i } <span class="sr-only">(current)</span></a></li>
			</c:forEach>	
			 <li <c:if test="${pageModelp.pageNum eq pageModelp.totalPages}"> class="disabled"</c:if>><a
						href="<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=${pageModelp.pageNum+1}"><span>&raquo;</span></a></li>
			 <li <c:if test="${pageModelp.pageNum eq pageModelp.totalPages}"> class="disabled"</c:if>><a
				href="<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=${pageModelp.totalPages}"><span>+&infin;</span></a></li>
			 <li><a>共${pageModelp.totalRecords}条记录</a></li>
			</ul>
			</nav>
	<center>
		<h1>应聘管理</h1>
	</center>
	<form id="applicationForm"
		action="<%=request.getContextPath()%>/CompanyServlet?command=main"
		method="post">
		职位名称<input type="text" name="positionName"
			value="${application.positionName }"> 申请时间<input
			id="startTime" class="Wdate" type="text"
			onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'endTime\')||\'2020-10-01\'}', dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
		- <input id="endTime" class="Wdate" type="text"
			onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startTime\')}',maxDate:'2020-10-01', dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
		申请状态<select name="status">
			<option value="">-全部-</option>
			<option value="1"
				<c:if test="${application.status==1 }">selected = "selected"</c:if>>待审核</option>
			<option value="2"
				<c:if test="${application.status==2 }">selected = "selected"</c:if>>通过</option>
			<option value="3"
				<c:if test="${application.status==3 }">selected = "selected"</c:if>>拒绝</option>
		</select> <input type="submit" value="查询" onclick="search()"
			class="btn btn-primary">
	</form>
	<table class="table table-striped ">
		<tr>
			<th>序 号</th>
			<th>人员名称</th>
			<th>职位名称</th>
			<th>申请状态</th>
			<th>申请时间</th>
			<th>操 作</th>
		</tr>

		<!--  foreach  展示申请信息 -->
		<c:forEach items="${pageModel.list }" var="app" varStatus="v">
			<tr>
				<td>${(pageModel.pageNum - 1) * pageModel.pageSum +v.count}</td>
				<td>${app.talentName }</td>
				<td>${app.positionName}</td>
				<td>${app.statusStr}</td>
				<td>${app.appTime}</td>
				<td><a onclick="pass(this,${app.id})" href="javascript:void(0);">通过</a>| <a onclick="refuse(this,${app.id})"  href="javascript:void(0);">拒绝</a></td>
			</tr>
		</c:forEach>
		<c:if test="${empty pageModel.list   }">
		<tr>
		<td colspan="6" align="center" class="alert alert-danger" role="alert">没有数据</td>
		</tr>
		</c:if>
		<tr>
			<td colspan="6" align="right">每页显示 <select id="pageSum">
					<option value="10" <c:if test="${pageModel.pageSum eq 10 }">selected="selected"</c:if>>10</option>
					<option value="30"<c:if test="${pageModel.pageSum eq 30}">selected="selected"</c:if>>30</option>
					<option value="50"<c:if test="${pageModel.pageSum eq 50 }">selected="selected"</c:if>>50</option>
			</select> 条 <a
				href="javascript:submitForm(<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=1);">首页</a>
				<c:if test="${pageModel.pageNum < pageModel.totalPages }">
					<a
						href="javascript:submitForm(<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=${pageModel.pageNum-1});">上一页</a>
				</c:if> 
				<c:if test="${pageModel.pageNum > pageModel.totalPages }">
					<a
						href="javascript:submitForm(<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=${pageModel.pageNum+1});">下一页</a>
				 <a
				href="javascript:submitForm(<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum=${pageModel.totalPages});">尾页</a>
	</c:if>
				<select id="page">
					<script>
			for(var i = 1;i<='${pageModel.totalPages}';i++){
				document.write("<option value="+i+">"+i+"</option>");
			}
			</script>
			</select> <input type="button" value="go" class="btn" onclick="goPage()">
				共${pageModel.totalRecords}条记录
			</td>
		</tr>
	</table>
</div>
<script>
function pass(obj,appId){
	$.get('<%=request.getContextPath()%>/ApplicationServlet?command=pass&applicationId='+ appId, function(text){
	     // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
	     if (text == 'fail') {
	    	layer.msg('操作失败！', {time: 2000, icon: 5});
	     } else {
	    	layer.msg('操作成功！', {time: 2000, icon: 6});
	    	$(obj.parentNode).prev().prev().text("审核通过");
	     }
	  });	
}
function refuse(obj,appId){
	$.get('<%=request.getContextPath()%>/ApplicationServlet?command=refuse&applicationId='+ appId, function(text){
	     // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
	     if (text == 'fail') {
	    	layer.msg('操作失败！', {time: 2000, icon: 5});
	     } else {
	    	layer.msg('操作成功！', {time: 2000, icon: 6});
	    	$(obj.parentNode).prev().prev().text("已拒绝");
	     }
	  });	
}

	function showInfo(){
		layer.open({type:1,skin:'layui-layer=rim',
			area:['420px','204px'].
			content='${position.name }'});
	}
	function deletePosition(positionId) {
		layer.confirm('确认删除？', {
		    btn: ['确认','取消'] //按钮
		}, function(){
		   location = '<%=request.getContextPath()%>/PositionServlet?command=deletePosition&positionId='
										+ positionId;
							});
		}
	if('${param.result}' === '0'){
		layer.msg('新增成功',{icon:1});
	}
	function goPage(){
		var page  = document.getElementById("page").value;
		var pageSum = document.getElementById("pageSum").value;
		location='<%=request.getContextPath()%>/CompanyServlet?command=main&pageNum='
				+ page + '&pageSum=' + pageSum;
	}
	function submitForm(url) {
		var form = document.getElementById("applicationForm");
		//把翻页的信息和查询的条件一起交给servlet
		form.action = url;
		form.submit();
	}
	
	function deletePosition(obj,appId){
		layer.confirm('确认删除？', {
		    btn: ['确认','取消'] //按钮
		}, function(){
	$.get('<%=request.getContextPath()%>/PositionServlet?command=deletePosition&positionId='+ appId, function(text){
	     // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
	     if (text == 'fail') {
	    	layer.msg('操作失败！', {time: 2000, icon: 5});
	     } else {
	    	layer.msg('操作成功！', {time: 2000, icon: 6});
	    	$(obj.parentNode.parentNode.parentNode.parentNode.parentNode).remove();
	     }
	  });
		});
	}
</script>
</body>
</html>